package mygame;

import com.jme3.math.Vector3f;
import com.jme3.scene.*;
import com.jme3.scene.VertexBuffer.Type;
import com.jme3.util.BufferUtils;

public class hexPrism 
{
    private float zLength, xWidth, yHeight, xPos,yPos,zPos;
    public hexPrism()
    {
        
    }
    public hexPrism(float xWidth,float yHeight,float zLength,float xPos,float yPos,float zPos)
    {
        
        this.xWidth = xWidth;
        this.yHeight = yHeight;
        this.zLength = zLength;
        this.xPos = xPos;
        this.yPos = yPos;
        this.zPos = zPos;
        
    }
    public Spatial creatHexPrism()
        {
             Mesh hexMesh = new Mesh();
            Vector3f [] vertices = new Vector3f[12]; //creating vertices
            //FRONT FACE
            vertices[0] = new Vector3f(xPos,yPos+(yHeight/2),zPos);//leftmost
            vertices[1] = new Vector3f(xPos+(xWidth/3),yPos,zPos);//bottom left
            vertices[2] = new Vector3f(xPos+(2*xWidth/3),yPos,zPos);//bottom right
            vertices[3] = new Vector3f(xPos+xWidth,yPos+(yHeight/2),zPos);//rightmost
            vertices[4] = new Vector3f(xPos+(2*xWidth/3),yPos+yHeight,zPos);//top right
            vertices[5] = new Vector3f(xPos+(xWidth/3),yPos+yHeight,zPos);//top left
            //BACK FACE
            vertices[6] = new Vector3f(xPos,yPos+(yHeight/2), zPos-zLength);//leftmost
            vertices[7] = new Vector3f(xPos+(xWidth/3),yPos,zPos-zLength);//bottom left
            vertices[8] = new Vector3f(xPos+(2*xWidth/3),yPos,zPos-zLength);//bottom right
            vertices[9] = new Vector3f(xPos+xWidth,yPos+(yHeight/2),zPos-zLength);//rightmost
            vertices[10] = new Vector3f(xPos+(2*xWidth/3),yPos+yHeight,zPos-zLength);//top right
            vertices[11] = new Vector3f(xPos+(xWidth/3),yPos+yHeight,zPos-zLength);//top left

            //texture coordinates
            /*
            Vector2f[] texCoord = new Vector2f[6];
            texCoord[0] = new Vector2f(0,0);
            texCoord[1] = new Vector2f(1,0);
            texCoord[2] = new Vector2f(0,1);
            texCoord[3] = new Vector2f(1,1);
            texCoord[4] = new Vector2f(0,0);
            texCoord[5] = new Vector2f(1,0);*/

            //lines separating front, back ,bottom, bottom right, top right
            //top, top left, bottom left
            int [] indexes = {5,0,1, 2,3,4, 4,5,1, 1,2,4, 
            7,6,11, 10,9,8, 7,11,10, 10,8,7,  
            2,1,7, 7,8,2,
            2,8,9, 9,3,2,  
            3,9,10, 10, 4, 3,   
            4,10,11, 11,5,4,
            5,11,6, 6,0,5,
            0,6,7, 7,1,0};

            hexMesh.setBuffer(Type.Position, 3, BufferUtils.createFloatBuffer(vertices));
            //hexMesh.setBuffer(Type.TexCoord, 2, BufferUtils.createFloatBuffer(texCoord));
            hexMesh.setBuffer(Type.Index,    1, BufferUtils.createIntBuffer(indexes));
            hexMesh.updateBound();

            Spatial hexGeom = new Geometry("ourmesh",hexMesh);
            //CANT SET MATERIAL HERE, asset manager gives error
            //SET MATERIAL IN MAIN CLASS
            //Common/MatDefs/Misc/ShowNormals.j3md rainbow colors
            //Material mat = new Material(assetManager, "Common/MatDefs/Misc/ShowNormals.j3md");
            //mat.setColor("Color",ColorRGBA.Red);
            //hexGeom.setMaterial(mat);
            //CANT ATTACH ROOT NODE HERE
            //INSTEAD RETURN THE SPATIAL
            //rootNode.attachChild(hexGeom);
            return hexGeom;
        }
}